package com.yonyou.brigade.third_parties.bfjr.controller;

import com.alibaba.fastjson.JSONObject;
import com.yonyou.brigade.basic_init.enums.ChannelEnum;
import com.yonyou.brigade.basic_init.model.BriChannel;
import com.yonyou.brigade.basic_init.service.IBriChannelService;
import com.yonyou.brigade.third_parties.bfjr.service.IBfjrOrderService;
import com.yonyou.brigade.util.resultutil.Msg;
import com.yonyou.brigade.util.resultutil.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/bfjr")
public class BfjrOrderInfoController {

    @Autowired
    private IBfjrOrderService bfjrOrderService;

    @Autowired
    private IBriChannelService briChannelService;
    /**
     * 手动拉取北方假日机票酒店订单
     * @param
     * @return
     */
    @RequestMapping("/flightAndHotelOrder")
    public Msg getBfjrFlightHotelOrder(@RequestBody Map param){
        List<BriChannel> briChannels = briChannelService.getEnableChannelByChannel(ChannelEnum.BFJR.getName());
        List<String> channelConfigList = new ArrayList<>();
        for (BriChannel briChannel : briChannels) {
             String config = briChannel.getConfig();
             String tenant = briChannel.getTenant();
             Integer channelId = briChannel.getId();
             JSONObject configObject = JSONObject.parseObject(config);
             String appId = configObject.getString("appId");
             if (channelConfigList.contains(appId)){
                continue;
             } else {
                channelConfigList.add(appId);
             }
            bfjrOrderService.getBrjrOrderList(appId,param,tenant,channelId);

        }
       return ResultUtil.success();
    }
}
